package com.dao.impl;

import com.dao.MysertDao;
import com.domain.Mysert;
import com.factory.OfficeFactory;

import java.util.ArrayList;

public class MysertDaoImpl implements MysertDao {
    @Override
    public Boolean save(Mysert mysert) {
        String sql = "insert into affair_management values(null,?,?,?)";

        return OfficeFactory.update(sql,mysert.getDate(),mysert.getAffair(),mysert.getRecorder());
    }

    @Override
    public Boolean delete(int id) {
        String sql = "delete from affair_management where id = ?";

        return OfficeFactory.update(sql,id);
    }

    @Override
    public ArrayList<Mysert> select() {
        String sql = "select * from affair_management";

        return OfficeFactory.select(new Mysert(),sql);
    }

    @Override
    public boolean update(Mysert mysert) {
        String sql = "UPDATE affair_management SET date = ? , affair = ? , recorder = ? " +
                " where id = ?";

        return OfficeFactory.update(sql,mysert.getDate(),mysert.getAffair(),mysert.getRecorder(),mysert.getId());
    }

    @Override
    public ArrayList<Mysert> selectByDate(String date) {
        String sql = "select * from affair_management  where date like ?";
        ArrayList<Mysert> select = OfficeFactory.select(new Mysert(), sql, "%" + date + "%");
        if(select != null && select.size() > 0) {
            return select;
        }
        return null;
    }
}
